package me.aartikov.sharedelementanimationsample;


import me.aartikov.alligator.DestinationType;
import me.aartikov.alligator.TransitionType;
import me.aartikov.alligator.animations.AnimationData;
import me.aartikov.alligator.animations.SimpleTransitionAnimation;
import me.aartikov.alligator.animations.TransitionAnimation;
import me.aartikov.alligator.animations.providers.TransitionAnimationProvider;
import me.aartikov.alligator.Screen;
import ohos.aafwk.ability.Ability;


public class SampleTransitionAnimationProvider implements TransitionAnimationProvider {

    public SampleTransitionAnimationProvider() {
    }

    @Override
    public TransitionAnimation getAnimation(TransitionType transitionType,
                                            DestinationType destinationType,
                                            Class<? extends Screen> screenClassFrom,
                                            Class<? extends Screen> screenClassTo,
                                            AnimationData animationData) {

        if (transitionType == TransitionType.FORWARD) {
            return createSlideAnimation(true, animationData);
        } else if (transitionType == TransitionType.BACK) {
            return createSlideAnimation(false, animationData);
        } else {
            return TransitionAnimation.DEFAULT;
        }
    }


    private TransitionAnimation createSlideAnimation(boolean forward, AnimationData animationData) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            Transition enterTransition = forward ? new Slide(Gravity.RIGHT) : new Slide(Gravity.LEFT);
//            Transition exitTransition = forward ? new Slide(Gravity.LEFT) : new Slide(Gravity.RIGHT);
//            LollipopTransitionAnimation animation = new LollipopTransitionAnimation(enterTransition, exitTransition);
//            animation.setAllowEnterTransitionOverlap(false);
//
//            Fragment currentFragment = mActivity.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
//            if (currentFragment instanceof SharedElementProvider) {
//                SharedElementProvider sharedElementProvider = (SharedElementProvider) currentFragment;
//                View sharedElement = sharedElementProvider.getSharedElement(animationData);
//                String shareElementName = sharedElementProvider.getSharedElementName(animationData);
//                animation.addSharedElement(sharedElement, shareElementName);
//                Transition moveTransition = TransitionInflater.from(mActivity).inflateTransition(Ohos.R.transition.move);
//                moveTransition.setDuration(600);
//                animation.setSharedElementTransition(moveTransition);
//            }
//            return animation;
//        } else {
//            int enterAnimRes = forward ? R.anim.slide_in_right : R.anim.slide_in_left;
//            int exitAnimRes = forward ? R.anim.slide_out_left : R.anim.slide_out_right;
//            return new SimpleTransitionAnimation(enterAnimRes, exitAnimRes);
//        }
        if(forward){
            return new SimpleTransitionAnimation(TransitionAnimation.RIRHT, TransitionAnimation.LEFT);
        }else{
            return new SimpleTransitionAnimation(TransitionAnimation.LEFT, TransitionAnimation.RIRHT);
        }
    }
}
